<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul{
            list-style: none;
            margin: 0;
            padding: 0;
            width: 200px;
            border: 1px solid #999;
        }
        li{
            border-bottom: 1px dashed #999;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <ul>
        <li><span><input type="checkbox" class="dsop"></span> 老友记</li>
        <li><span><input type="checkbox" class="dsop"></span> 爱情公寓</li>
        <li><span><input type="checkbox" class="dsop"></span> 请回答1988</li>
        <li><span><input type="checkbox" class="dsop"></span> 山海情</li>
        <li><span><input type="checkbox" class="dsop"></span> 还珠格格</li>
        <li><span><input type="checkbox" class="dsop"></span> 甲方乙方</li>
        <li>
            <span><input type="checkbox" class="all"> 全选</span>
            <span><input type="checkbox" class="rever"> 反选</span>
        </li>
    </ul>

    <script>
        let aP = document.getElementsByClassName('dsop');
        let oAll = document.getElementsByClassName('all')[0];
        let oRe = document.getElementsByClassName('rever')[0];

        oAll.onchange = function(){
            for(let i = 0;i < aP.length;i++){
                aP[i].checked = oAll.checked;
            }
        }
        // 检查选项，判断 全选 是否需要勾选
        function checkAll(){
            let bool = true;
            for(let i = 0;i < aP.length;i++){
                if(aP[i].checked == false){
                    bool = false;
                }
            }
            oAll.checked = bool;
        }
        // 给每一个选项绑定change事件
        for(let i = 0;i < aP.length;i++){
            aP[i].onchange = function(){
                checkAll();
            } 
        }

        oRe.onchange = function(){
            for(let i = 0;i < aP.length;i++){
                aP[i].checked = !aP[i].checked;
                checkAll();
            }
        }

    </script>
</body>
</html>